package com.ruoyi.kanfang.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kanfang.domain.BuildingDetailInfo;
import com.ruoyi.kanfang.service.IBuildingDetailInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品房信息Controller
 * 
 * @author limin
 * @date 2024-04-30
 */
@RestController
@RequestMapping("/kanfang/info")
public class BuildingDetailInfoController extends BaseController
{
    @Autowired
    private IBuildingDetailInfoService buildingDetailInfoService;

    /**
     * 查询商品房信息列表
     */
    @PreAuthorize("@ss.hasPermi('kanfang:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuildingDetailInfo buildingDetailInfo)
    {
        startPage();
        List<BuildingDetailInfo> list = buildingDetailInfoService.selectBuildingDetailInfoList(buildingDetailInfo);
        return getDataTable(list);
    }

    /**
     * 导出商品房信息列表
     */
    @PreAuthorize("@ss.hasPermi('kanfang:info:export')")
    @Log(title = "商品房信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuildingDetailInfo buildingDetailInfo)
    {
        List<BuildingDetailInfo> list = buildingDetailInfoService.selectBuildingDetailInfoList(buildingDetailInfo);
        ExcelUtil<BuildingDetailInfo> util = new ExcelUtil<BuildingDetailInfo>(BuildingDetailInfo.class);
        util.exportExcel(response, list, "商品房信息数据");
    }

    /**
     * 获取商品房信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('kanfang:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(buildingDetailInfoService.selectBuildingDetailInfoById(id));
    }

    /**
     * 新增商品房信息
     */
    @PreAuthorize("@ss.hasPermi('kanfang:info:add')")
    @Log(title = "商品房信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuildingDetailInfo buildingDetailInfo)
    {
        return toAjax(buildingDetailInfoService.insertBuildingDetailInfo(buildingDetailInfo));
    }

    /**
     * 修改商品房信息
     */
    @PreAuthorize("@ss.hasPermi('kanfang:info:edit')")
    @Log(title = "商品房信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuildingDetailInfo buildingDetailInfo)
    {
        return toAjax(buildingDetailInfoService.updateBuildingDetailInfo(buildingDetailInfo));
    }

    /**
     * 删除商品房信息
     */
    @PreAuthorize("@ss.hasPermi('kanfang:info:remove')")
    @Log(title = "商品房信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(buildingDetailInfoService.deleteBuildingDetailInfoByIds(ids));
    }

    @GetMapping("/initData/{serialNum}")
    @Anonymous
    public AjaxResult initData(@PathVariable("serialNum") String serialNum){
        // 初始化数据
        return buildingDetailInfoService.initData(serialNum);
    }

    @GetMapping("/processData")
    @Anonymous
    public AjaxResult dataProcess(){
        // 数据加工
        buildingDetailInfoService.dataProcess();
        return success();
    }
}
